package com.example.mys_app;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import org.w3c.dom.Text;

public class Activity2 extends AppCompatActivity {


    @Override
    protected void onPause() {
        super.onPause();
        Log.d("sh","2:onPause...");
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        Log.d("sh","2:onPostResume...");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("sh","2:onResume...");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("sh","2:onDestroy...");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("sh","2:onStop...");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("sh","2:onStart...");
    }

    ImageView imageView;
    Button button1,button2;
    TextView textView1,textView2;
    int songIndex=-1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_2);

        Log.d("sh","2:onCreate...");

        imageView=findViewById(R.id.imageView);
        textView1=findViewById(R.id.textView2);
        textView2=findViewById(R.id.textView6);
        button1=findViewById(R.id.button9);
        button2=findViewById(R.id.button10);
        Intent intent=getIntent();
        Intent intent1=new Intent(Activity2.this,MyService.class);


        String songname=intent.getStringExtra("songname");
        String songername=intent.getStringExtra("songername");
        textView1.setText("歌名     "+songname);
        textView2.setText("歌手     "+songername);

        //将点击的歌曲名称设置对应的索引
        if (songname.equals("七里香"))
            songIndex=0;
        else if (songname.equals("晴天")) {
            songIndex=1;
        } else if (songname.equals("兰亭序")) {
            songIndex=2;
        }

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intent1.putExtra("songIndex",songIndex);
                startService(intent1);
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                stopService(intent1);
                finish();
            }
        });

    }
}